var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page: 1,
    type: 1,
    
    tip: '上拉加载',
    loading: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.loadlist();
  },
  loadlist: function() {
    let that = this;
    that.setData({
      tip: '正在加载',
      loading: true
    })
    app.http.$ajax({
      url: 'v1.task/taskMoney',
      data: {
        page: this.data.page,
        type: this.data.type,
      },
      loading: false
    }, {
      success: (res) => {
        that.data.list.push(...res.data.data);
        that.data.page ++;
        let pagedata = app.util.pageshow(res.data);
        that.setData({
          page: that.data.page ,
          list: that.data.list,
          ...pagedata
        })
      }
    })
  },
 
  changetype: function (e) {
    let type = e.target.dataset.type;
    this.setData({
      type: type,
      list: [],
      page: 1
    })
   this.loadlist()
  },
  wancheng: function () {
    this.setData({
      type: 2,
      list: [],
      hasmore: true
    })
    this.loadlist(1, 2, this.data.month)

  },
  

  onReachBottom() {
    //滚动到底部
    if(this.data.tip != '没有更多数据') {
        this.loadlist()
    }
},

  gotoRate() {
    wx.navigateTo({
      url: '/pages/rate/geshui',
    })
  },
  //时间
  bindDateChange(e){
    let theDate = e.detail.value;
    this.setData({
      date: theDate
    })
  },
  binderrorimg(event) {
    let index = event.target.dataset.index;
    var img = 'list[' + index + '].photo_path'
    this.setData({
      [img]: '/images/zhanweitu.png'
    })   
  }, 
  //跳转到众保费确认
  gotoConfirm(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/rate/confirm?id=' + id,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    this.data.list = [];
    that.loadlist(1, that.data.type, that.data.month);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    this.setData({
      isLoading: true
    });
    if (that.data.hasmore) {
      var page = that.data.page;
      page += 1;
      that.setData({ page: page })
      that.loadlist(page, that.data.type,that.data.month);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})